package com.zmn.oms.admin.config;

import com.zmn.oms.common.constant.CdsConsts;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

/**
 * 类描述：
 *
 * @author LiangHailong
 * @since 2022-05-16 12:02
 */
@Slf4j
@Component
public class EnvironmentConfig implements EnvironmentAware {
    private Environment env;

    @Override
    public void setEnvironment(Environment environment) {
        env = environment;

        this.initConsts(environment);
    }

    // 利用配置初始化伪常量
    private void initConsts(Environment env) {
        log.info("=========================== 伪常量初始化 ===========================");
        {// CDS调用
            CdsConsts.HttpCall.BASE_URL = env.getProperty("cds.api.base-url");
            log.info("cds.api.base-url=[{}]", CdsConsts.HttpCall.BASE_URL);
            CdsConsts.HttpCall.MODEL_NAME = env.getProperty("cds.api.app-name");
            log.info("cds.api.app-name=[{}]", CdsConsts.HttpCall.MODEL_NAME);
            CdsConsts.HttpCall.SECRET_KEY = env.getProperty("cds.api.secretkey");
            log.info("cds.api.secretkey=[{}]", CdsConsts.HttpCall.SECRET_KEY);
        }
        log.info("=========================== 伪常量初始化结束 ===========================");
    }
}
